package com.java.base.thread;

import java.util.concurrent.locks.ReentrantLock;

public class TestDeadLock {


    static ReentrantLock lockA;
    static ReentrantLock lockB;

    static {
        lockA = new ReentrantLock();
        lockB = new ReentrantLock();
    }

    public static void main(String[] args) {

        new Thread(() -> {
            lockA.lock();

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            lockB.lock();

            lockA.unlock();
            lockB.unlock();


        }).start();


        new Thread(() -> {
            lockB.lock();

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            lockA.lock();


            lockB.unlock();
            lockA.unlock();
        }).start();

    }


}
